using Microsoft.Phone.Controls.Primitives;
using System;
using System.Collections.Generic;
namespace MicroMsg.UI.Page
{
	internal class ProviceDataSource : LoopingDataSourceBase
	{
		private Dictionary<string, List<AreaItem>> provinceCityMap;
		private LoopingSelector citySelector;
		private List<AreaItem> provinces;
		public ProviceDataSource(Dictionary<string, List<AreaItem>> provinceCityMap, LoopingSelector citySelector, List<AreaItem> provinces)
		{
			this.provinceCityMap = provinceCityMap;
			this.citySelector = citySelector;
			this.provinces = provinces;
			base.SelectedItem = provinces.get_Item(0);
		}
		protected override void OnSelectionChanged(object oldSelectedItem, object newSelectedItem)
		{
			string areaName = ((AreaItem)newSelectedItem).areaName;
			List<AreaItem> citys = this.provinceCityMap.get_Item(areaName);
			this.citySelector.DataSource = new CityDataSource(citys);
		}
		public override object GetNext(object relativeTo)
		{
			if (relativeTo == null)
			{
				return null;
			}
			int index = ((AreaItem)relativeTo).index;
			if (index > this.provinces.get_Count() - 2)
			{
				return null;
			}
			return this.provinces.get_Item(index + 1);
		}
		public override object GetPrevious(object relativeTo)
		{
			if (relativeTo == null)
			{
				return null;
			}
			int index = ((AreaItem)relativeTo).index;
			if (index < 1)
			{
				return null;
			}
			return this.provinces.get_Item(index - 1);
		}
	}
}
